package com.dao;
 
import com.model.*;
import java.util.ArrayList;
import java.util.List;
import org.hibernate.*;
import org.hibernate.criterion.Restrictions;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
 
// Referenced classes of package com.dao:
//            UserDao
 
public class UserDaoImpl
    implements UserDao
{
 
    public UserDaoImpl()
    {
        session = null;
    }
 
    public void addUser(UserDetail user)
    {
        session = getSessionFactory().getCurrentSession();
        getSessionFactory().getCurrentSession().save(user);
    }
 
    public void updateUser(UserDetail user)
    {
        getSessionFactory().getCurrentSession().update(user);
    }
 
    public void deleteUser(UserDetail user)
    {
        getSessionFactory().getCurrentSession().delete(user);
    }
 
    public UserDetail getUserById(string userId)
    {
        list list;
        session = getSessionFactory().getCurrentSession();
        list = getSessionFactory().getCurrentSession().createQuery("from UserDetail ud where ud.userId =?").setParameter(0, userId).list();
        return (UserDetail)list.get(0);
        exception e;
        e;
        e.printStackTrace();
        return null;
    }
 
    public list getUsers()
    {
        list list = getSessionFactory().getCurrentSession().createQuery("from UserDetail").list();
        return list;
    }
 
    public SessionFactory getSessionFactory()
    {
        return sessionFactory;
    }
 
    public void setSessionFactory(SessionFactory sessionFactory)
    {
        this.sessionFactory = sessionFactory;
    }
 
    public list getUserRoles(string userId)
    {
        list authorities = new arraylist();
        UserRoleMapping mapDetail = (UserRoleMapping)getSessionFactory().getCurrentSession().createCriteria(com/model/UserRoleMapping).add(Restrictions.eq("userDetail.userNo", integer.valueOf(getUserById(userId).getUserNo()))).uniqueResult();
        if(mapDetail != null)
            authorities.add(new SimpleGrantedAuthority(mapDetail.getRoleMaster().getRoleDesc()));
        return authorities;
    }
 
    private static final long serialVersionUID = 1L;
    Session session;
    private SessionFactory sessionFactory;
}